<%--管理员-博客添加--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <meta charset="utf-8">
    <title>图形图像处理交流网站</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/public.css" media="all">
    <style>
        .layui-form-select dl {
            z-index: 9999;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layui-form-pane">
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    <form:form class="layui-form" action="" method="post">
                        <div class="layui-row layui-col-space15 layui-form-item">
                            <div class="layui-col-md4">
                                <label class="layui-form-label">选择分类</label>
                                <div class="layui-input-block">
                                    <select lay-verify="required" name="tId">
                                            <%--<option value="${blog.tId}" selected="selected">${blog.type.tName}</option>--%>
                                        <c:forEach items="${typelist}" var="typelist">
                                            <c:if test="${blog.tId==typelist.tId}">
                                                <option value="${typelist.tId}"
                                                        selected="selected">${typelist.tName}</option>
                                            </c:if>
                                            <c:if test="${blog.tId!=typelist.tId}">
                                                <option value="${typelist.tId}">${typelist.tName}</option>
                                            </c:if>

                                        </c:forEach>

                                    </select>
                                </div>
                            </div>
                            <div class="layui-col-md7">
                                <label for="L_title" class="layui-form-label">标题</label>
                                <div class="layui-input-block">
                                    <input type="hidden" name="bId" value="${blog.bId}">
                                    <input type="text" id="L_title" name="bTitle" value="${blog.bTitle}" required
                                           lay-verify="required" autocomplete="off" class="layui-input">

                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item layui-form-text">
                            <!--百度富文本编辑器-->
                            <textarea id="bContent" lay-verify="required" name="bContent" style="width:100%;height:500px;">
                                    ${blog.bContent}
                            </textarea>

                        </div>
                        <div class="layui-form-item">
                            <button class="layui-btn" lay-submit lay-filter="editForm">立即修改</button>
                        </div>
                    </form:form>
                </div>
            </div>
        </div>
        <%--中间内容结束--%>
    </div>
</div>
<script type="text/javascript" charset="utf-8"
        src="${pageContext.request.contextPath}/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
        src="${pageContext.request.contextPath}/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
<script src="${pageContext.request.contextPath}/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.config({
        version: "3.0.0"
        , base: '${pageContext.request.contextPath}/js/'
    }).extend({
        fly: 'index'
    }).use('fly');
</script>
<!--导航栏-->
<script>
    layui.use('element', function () {
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

        //监听导航点击
        element.on('nav(demo)', function (elem) {
            //console.log(elem)
            layer.msg(elem.text());
        });
    });
</script>
<!-- UEditor 编辑器实例化 -->
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('bContent');
</script>
<%--提交表单--%>
<script>
    layui.use(['layer','form'],function(){
        var form=layui.form;
        var layer=layui.layer;
        form.on('submit(editForm)', function(data){
            console.log(data.field);
            $.ajax({
                url:'${pageContext.request.contextPath}/admin/blog/edit.do',
                method:'post',
                data:data.field,
                dataType:'JSON',
                success:function(res){
                    if(res.code == 200){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.msg(res.msg, {icon: 1});
                        parent.layui.table.reload('test');//重载父页表格，参数为表格ID
                        parent.layer.close(index);
                    }
                    else
                        parent.layer.msg(res.msg, {icon: 2});
                },
                error:function (data) {

                }
            }) ;

        });
    });
</script>

</body>
</html>
